/**
 * 响应拦截
 * @param {Object} http
 */
import { removeToken } from '@/util/auth.js'
module.exports = (vm) => {
	uni.$u.http.interceptors.response.use(
		(response) => {
			/* 对响应成功做点什么 可使用async await 做异步操作*/
			const data = response.data;
			uni.hideLoading();
			if (data.code == "401") {
				uni.showToast({
					title: '用户过期，请重新登录',
					duration: 2000
				});
				removeToken()
				uni.redirectTo({
					url: "/pages/index/login",
				});
				return Promise.reject(data);
			}
			return data || {};
		}
	);
};
